package com.merlin.demo_wellshape.repository;

import com.merlin.demo_wellshape.pojo.ExercisePlan;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.LocalDate;
import java.util.List;

public interface ExercisePlanRepository extends JpaRepository<ExercisePlan, Integer> {
    // 检查用户当天是否已经计划了该运动
    @Query("SELECT CASE WHEN COUNT(e) > 0 THEN true ELSE false END " +
            "FROM ExercisePlan e " +
            "WHERE e.dailyPlan.user.userId = :userId " +
            "AND e.dailyPlan.planDate = :planDate " +
            "AND e.planName = :planName " +
            "AND e.quantity = :quantity")
    // 参数绑定
    boolean existsByDailyPlan_User_UserIdAndDailyPlan_PlanDateAndPlanNameAndQuantity(
            @Param("userId") int userId,
            @Param("planDate") LocalDate planDate,
            @Param("planName") String planName,
            @Param("quantity") String quantity);

    // 根据 DailyPlanId 查询所有 ExercisePlan
    List<ExercisePlan> findByDailyPlan_DailyPlanId(int dailyPlanId);
}
